$(function () {
    getUserInfo()


    $('logout').click(function () {
        layer.confirm('确定退出登录', { icon: 3, title: '提示' }, function (index) {
            localStorage.removeItem('token')
            location.href = '/login.html'
            layer.close(index)
        })
    })
})
function getUserInfo() {
    axios({
        url: "/my/userinfo",
        // headers: {
        //     Authorization: localStorage.getItem('token')
        // }
    }).then(res => {
        // console.log(res.data);
        if (res.data.status !== 0) {
            return  layui.layer.msg(res.data.message)

        }
        renderAvater(res.data.data)

    })
    function renderAvater(user) {
        let first = user.nickname || user.username
        $(".weclome").html('欢迎&nbsp;' + name)
        if (user.user_pic !== null) {
            $('.avatar.text').hide()
            $('layer-nav-img').show().attr('src',user.user_pic)
        } else {
            $('.layer-nav-img').hide()
            $('.avatar.text').show().html(first)
        }
    }
}

